﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

namespace odinshrine
{
    class Boss : Humain
    {
        public static int Points = 5;
        Texture2D barreVie;
        bool dessine = true;

        public void Load(ContentManager Content)
        {
            texture = Content.Load<Texture2D>("ennemi");
            barreVie = Content.Load<Texture2D>("vie");
            Position.X = 1000;
            Position.Y = 300;
            Vitesse = 4;
            Vie = 500;
        }

        public void DrawBoss(SpriteBatch spriteBatch)
        {
            if (dessine)
            {
                spriteBatch.Draw(texture, new Vector2(Position.X, Position.Y), Color.PaleGreen);
                spriteBatch.Draw(barreVie, new Rectangle((int)Position.X, (int)Position.Y, Vie/4, barreVie.Height), Color.Orange);
            }
        }

        private void Scrolling(Joueur player, KeyboardState clavier, GraphicsDeviceManager graphics)
        {
            if (clavier.IsKeyDown(Keys.D) && player.Position.X + player.width >= graphics.PreferredBackBufferWidth / 2)
            {
                Position.X -= player.Vitesse;
            }
        }

        public void Gestion(Arme arme, Joueur player, KeyboardState clavier, GraphicsDeviceManager graphics, Sprite balle, GestionPhysics physEngine)
        {
            Scrolling(player, clavier, graphics);
            if (Vie == 0)
            {
                dessine = false;
            }
            if (Position.X - player.Position.X <= 600) //On lance l'IA de l'ennemi que si le joueur est proche de lui
            {
                for (int i = 0; i < 100; i++)
                {
                    if (physEngine.collisionRectangleRectangle(new Rectangle(player.ballesListe.tableau[i, 0], player.ballesListe.tableau[i, 1], balle.Texture.Width, balle.Texture.Height), new Rectangle((int)Position.X, (int)Position.Y, (int)(texture.Width), (int)(texture.Height))))
                    {
                        Vie -= arme.puissance;
                        player.ballesListe.tableau[i, 0] = -1;
                        player.ballesListe.tableau[i, 1] = -1;
                    }
                }
                IA(player);
            }
        }

        private void IA(Joueur player)
        {
            
        }
    }
}
